package com.jeeplus.test.jlnu.admissionInfo.service.impl;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jeeplus.sys.service.OfficeService;
import com.jeeplus.test.education.domain.vo.EducationInfoVo;
import com.jeeplus.test.education.mapper.EducationInfoMapper;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.AdmissionInfo;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.ImportFailLog;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.JlnuTeachingArchives;
import com.jeeplus.test.jlnu.admissionInfo.domain.entity.Supplement;
import com.jeeplus.test.jlnu.admissionInfo.domain.vo.AdmissionInfoDto;
import com.jeeplus.test.jlnu.admissionInfo.domain.vo.AdmissionInfoReqVo;
import com.jeeplus.test.jlnu.admissionInfo.domain.vo.AdmissionInfoRespVo;
import com.jeeplus.test.jlnu.admissionInfo.mapper.AdmissionInfoMapper;
import com.jeeplus.test.jlnu.admissionInfo.mapper.ExcelMapper;
import com.jeeplus.test.jlnu.admissionInfo.service.AdmissionInfoService;
import com.jeeplus.test.jlnu.admissionInfo.utils.GrayStyleHandler;
import com.jeeplus.test.jlnu.archivalInfo.domain.entity.ArchivalInfo;
import com.jeeplus.test.jlnu.deanOffice.domain.vo.JlnuDeansOfficeDto;
import com.jeeplus.test.jlnu.deanOffice.mapper.DeansOfficeMapper;
import com.jeeplus.test.jlnu.degreeInfo.domain.entity.DegreeInfo;
import com.jeeplus.test.jlnu.employmentInfo.domain.entity.EmploymentInfo;
import com.jeeplus.test.jlnu.fieldConfig.domain.FieldConfigEntity;
import com.jeeplus.test.jlnu.fieldConfig.mapper.AdmissionFieldConfigMapper;
import com.jeeplus.test.jlnu.graduationInfo.domain.entity.GraduationInfo;
import com.jeeplus.test.jlnu.mailingInfo.domain.entity.MailingInfo;
import com.jeeplus.test.jlnu.qualificationInfo.domain.entity.QualificationInfo;
import com.jeeplus.test.jlnu.studentStatusInfo.domain.entity.StudentStatusInfo;
import com.jeeplus.test.postgraduate.domain.vo.PostgraduateReqVo;
import com.jeeplus.test.postgraduate.mapper.PostgraduateMapper;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.ss.usermodel.WorkbookFactory;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.Field;
import java.util.*;
import java.util.stream.Collectors;

@Service
public class AdmissionInfoServiceImpl implements AdmissionInfoService {

    @Autowired
    private AdmissionInfoMapper admissionInfoMapper;

    @Autowired
    private AdmissionFieldConfigMapper admissionFieldConfigMapper;

    @Autowired
    private ExcelMapper excelMapper;

    @Autowired
    private DeansOfficeMapper deansOfficeMapper;

    @Autowired
    private PostgraduateMapper postgraduateMapper;

    @Autowired
    private EducationInfoMapper educationInfoMapper;

    @Autowired
    private OfficeService officeService;
    @Override
    public Page<Map<String, Object>> getAdmissionInfoPage(AdmissionInfoReqVo admissionInfoReqVo,Page<AdmissionInfoRespVo> page) {
        // 1. 获取分页结果和字段配置信息
        if(StringUtils.isNotEmpty(admissionInfoReqVo.getOfficeId())){
            //获取机构下所有层级
            List<String> officesList = officeService.getOfficesTreeByParentId(admissionInfoReqVo.getOfficeId());
            officesList.add(admissionInfoReqVo.getOfficeId());
            admissionInfoReqVo.setOfficesList(officesList);
        }
        if (StringUtils.isNotEmpty(admissionInfoReqVo.getApproveState())) {
            String[] arr = admissionInfoReqVo.getApproveState().split(",");
            List<String> list = Arrays.asList(arr);
            admissionInfoReqVo.setApproveStateList(list);
        }

        if (StringUtils.isNotEmpty(admissionInfoReqVo.getTransferState())) {
            String[] arr = admissionInfoReqVo.getTransferState().split(",");
            List<String> list = Arrays.asList(arr);
            admissionInfoReqVo.setTransferStateList(list);
        }
        //提取对象参数(1：教务处，2：研究生，3：继续教育)
        Field[] admissionInfoReqVoFields = FieldUtils.getAllFields(AdmissionInfoReqVo.class);
        List<String> admissionInfoReqVoNames = Arrays.stream(admissionInfoReqVoFields).map(Field::getName).collect(Collectors.toList());
        String subtableAs = null;
        List<String> subtableData = null;
        switch (admissionInfoReqVo.getRecordType()){
            case "1":
                //1：教务处
                subtableAs = " x.";
                Field[] jlnuDeansOfficeDtoFields = FieldUtils.getAllFields(JlnuDeansOfficeDto.class);
                subtableData = Arrays.stream(jlnuDeansOfficeDtoFields).map(Field::getName).collect(Collectors.toList());
                break;
            case "2":
                //2：研究生
                subtableAs = " y.";
                Field[] postgraduateReqVoFields = FieldUtils.getAllFields(PostgraduateReqVo.class);
                subtableData = Arrays.stream(postgraduateReqVoFields).map(Field::getName).collect(Collectors.toList());
                break;
            case "3":
                //3：继续教育
                subtableAs = " z.";
                Field[] educationInfoVoFields = FieldUtils.getAllFields(EducationInfoVo.class);
                subtableData = Arrays.stream(educationInfoVoFields).map(Field::getName).collect(Collectors.toList());
                break;
        }

        //获取组装条件
        List<String> finalSubtableData = subtableData;
        String finalSubtableAs = subtableAs;
        if(admissionInfoReqVo.getConditions() != null){
            admissionInfoReqVo.getConditions().forEach(condition -> {
                //确定条件属于什么表
                if(admissionInfoReqVoNames.stream()
                        .map(String::toLowerCase)
                        .collect(Collectors.toList())
                        .contains(condition.getField().toLowerCase())){
                    condition.setQuerySql(" a." + condition.getField());
                }else if(
                finalSubtableData.stream()
                        .map(String::toLowerCase)
                        .collect(Collectors.toList())
                        .contains(condition.getField().toLowerCase())){
                    condition.setQuerySql(finalSubtableAs + condition.getField());
                }
            });
        }

        Page<AdmissionInfoRespVo> admissionInfoPage = admissionInfoMapper.getAdmissionInfoPage(admissionInfoReqVo, page);
        List<FieldConfigEntity> allFieldConfigs = admissionFieldConfigMapper.getAllFieldConfigs();
        List<AdmissionInfoRespVo> records = admissionInfoPage.getRecords();

        List<Map<String, Object>> modifiedRecords = new ArrayList<>();

        // 2. 遍历每条记录
        for (AdmissionInfoRespVo record : records) {


                //教务处数据填充
                JlnuDeansOfficeDto jlnuDeansOfficeDto = new JlnuDeansOfficeDto();
                jlnuDeansOfficeDto.setXH(record.getStudentId());
                jlnuDeansOfficeDto.setKSH(record.getExamineeNum());
                jlnuDeansOfficeDto.setZKZH(record.getAdmissionNum());
                jlnuDeansOfficeDto.setSFZH(record.getIdCard());
                jlnuDeansOfficeDto.setOfficeId(admissionInfoReqVo.getOfficeId());
                record.setJlnuDeansOffice(deansOfficeMapper.selectAdmissionInfoByRecord(jlnuDeansOfficeDto));
                //数据填充研究生
                PostgraduateReqVo postgraduateReqVo = new PostgraduateReqVo();
                postgraduateReqVo.setZxshxh(record.getStudentId());
                postgraduateReqVo.setZh(record.getExamineeNum());
                postgraduateReqVo.setZkzh(record.getAdmissionNum());
                postgraduateReqVo.setOfficeId(admissionInfoReqVo.getOfficeId());
                postgraduateReqVo.setSfzh(record.getIdCard());
                record.setPostgraduate(postgraduateMapper.selectAdmissionInfoByRecord(postgraduateReqVo));

                //数据填充研究生
                EducationInfoVo educationInfoVo = new EducationInfoVo();
                educationInfoVo.setStudentId(record.getStudentId());
                educationInfoVo.setKsh(record.getExamineeNum());
                educationInfoVo.setZkzh(record.getAdmissionNum());
                educationInfoVo.setOfficeId(admissionInfoReqVo.getOfficeId());
                educationInfoVo.setSfzh(record.getIdCard());
                record.setEducationInfo(educationInfoMapper.selectAdmissionInfoByRecord(educationInfoVo));



            Map<String, Object> recordMap = new HashMap<>();

            // 3. 将 AdmissionInfoRespVo 中的字段放入 map
            Field[] fields = AdmissionInfoRespVo.class.getDeclaredFields();
            for (Field field : fields) {
                field.setAccessible(true);
                try {
                    // 获取字段值并添加到 map 中
                    Object value = field.get(record);
                    recordMap.put(field.getName(), value);
                } catch (IllegalAccessException e) {
                    e.printStackTrace();
                }
            }

            // 4. 根据配置处理自定义字段
            for (FieldConfigEntity config : allFieldConfigs) {
                String originalField = config.getFieldKey();  // 原始字段名
                String customField = config.getFieldName();   // 自定义字段名

                try {
                    // 获取 AdmissionInfoRespVo 中的原始字段
                    Field originalFieldObj = AdmissionInfoRespVo.class.getDeclaredField(originalField);
                    originalFieldObj.setAccessible(true);

                    // 获取字段值
                    Object value = originalFieldObj.get(record);
                    String prefixedCustomField = "custom_" + customField;

                    // 无论值是否为 null，都将自定义字段名作为 key 放入 map
                    recordMap.put(prefixedCustomField, value);  // 即使 value 为 null 也会添加 key

                    // 如果需要删除原始字段，可以选择性移除
                    recordMap.remove(originalField); // 删除原始字段，保留自定义字段
                } catch (NoSuchFieldException | IllegalAccessException e) {
                    e.printStackTrace();
                    // 如果字段不存在，依然将 key 放入 map，并设置为 null
                    recordMap.put("custom_" + customField, null);  // 将字段名存入 map，值为 null
                }
            }

            // 5. 添加处理后的记录
            modifiedRecords.add(recordMap);
        }
        admissionInfoPage.setRecords(records);

        // 6. 将处理后的记录封装到新的分页对象中返回
        Page<Map<String, Object>> modifiedPage = new Page<>(admissionInfoPage.getCurrent(), admissionInfoPage.getSize(), admissionInfoPage.getTotal());
        modifiedPage.setRecords(modifiedRecords);

        return modifiedPage;

    }

    @Override
    public int batchUpdate(List<String> studentIds, AdmissionInfoDto admissionInfoDto) {
        admissionInfoMapper.updateTeacherData(studentIds,admissionInfoDto);
        return admissionInfoMapper.batchUpdate(studentIds,admissionInfoDto);
    }

    @Override
    public Supplement selectNullByStuId(String stuId) {
        Supplement supplement = admissionInfoMapper.selectNullByStuId(stuId);
        return supplement;
    }

    @Override
    public int updateArchival(Supplement supplement) {
        ArchivalInfo archivalInfo = new ArchivalInfo();
        DegreeInfo degreeInfo = new DegreeInfo();
        EmploymentInfo employmentInfo = new EmploymentInfo();
        GraduationInfo graduationInfo = new GraduationInfo();
        MailingInfo mailingInfo = new MailingInfo();
        QualificationInfo qualificationInfo = new QualificationInfo();
        StudentStatusInfo studentStatusInfo = new StudentStatusInfo();
        AdmissionInfo admissionInfo = new AdmissionInfo();
        BeanUtils.copyProperties(supplement, admissionInfo);
        BeanUtils.copyProperties(supplement, archivalInfo);
        BeanUtils.copyProperties(supplement, degreeInfo);
        BeanUtils.copyProperties(supplement, employmentInfo);
        BeanUtils.copyProperties(supplement, graduationInfo);
        BeanUtils.copyProperties(supplement, mailingInfo);
        BeanUtils.copyProperties(supplement, qualificationInfo);
        BeanUtils.copyProperties(supplement, studentStatusInfo);
        admissionInfoMapper.updateArchival(archivalInfo);
        admissionInfoMapper.updateDegreeInfo(degreeInfo);
        admissionInfoMapper.updateEmploymentInfo(employmentInfo);
        admissionInfoMapper.updateGraduationInfo(graduationInfo);
        admissionInfoMapper.updateMailingInfo(mailingInfo);
        admissionInfoMapper.updateQualificationInfo(qualificationInfo);
        admissionInfoMapper.updateStudentStatusInfo(studentStatusInfo);
        admissionInfoMapper.updateAdmissions(admissionInfo);
        return 1;
    }

    @Override
    public void insertAdmission(AdmissionInfo admissionInfo) {
        admissionInfoMapper.insertAdmission(admissionInfo);
    }

    @Override
    public int insertAdmissions(List<AdmissionInfo> admissionInfos) {
        for (AdmissionInfo admissionInfo : admissionInfos) {
            if(admissionInfoMapper.checkStudentId(admissionInfo.getStudentId())>0){
                return -1;
            }
        }
        // 插入录取信息表全部数据
        excelMapper.saveFirstData(admissionInfos);
        excelMapper.saveTec(admissionInfos);
        // 插入学籍信息表（只插入学号）
        excelMapper.saveSecondData(admissionInfos);
        // 插入毕业信息表（只插入学号）
//        excelMapper.saveThirdData(admissionInfos);
        // 插入就业信息表（只插入学号）
        excelMapper.saveFourth(admissionInfos);
        // 插入学位信息表（只插入学号）
        excelMapper.saveFifth(admissionInfos);
        // 插入学历信息表（只插入学号）
        excelMapper.saveSixth(admissionInfos);
        // 插入转递（邮寄信息表）
        excelMapper.saveSeventh(admissionInfos);
        // 档案信息表
//        excelMapper.saveEighth(admissionInfos);
        excelMapper.saveFourteenth(admissionInfos);
        excelMapper.saveFifteenth(admissionInfos);
        // 创建两个列表来存储不同 flag 的对象
        List<AdmissionInfo> flagOneList = new ArrayList<>();
        List<AdmissionInfo> otherFlagList = new ArrayList<>();

        for (AdmissionInfo admissionInfo : admissionInfos) {

            if(admissionInfo.getGradation().equals("本科")){
                admissionInfo.setFlag("1");
            }else if(admissionInfo.getGradation().equals("硕士")){
                admissionInfo.setFlag("2");
            }else {
                admissionInfo.setFlag("3");
            }
            if ("1".equals(admissionInfo.getFlag())) {
                flagOneList.add(admissionInfo);
            } else {
                otherFlagList.add(admissionInfo);
            }
        }

        // 对于 flag 为 1 的对象调用保存方法
        if (!flagOneList.isEmpty()) {
            excelMapper.saveNinth(flagOneList);
            excelMapper.saveTenth(flagOneList);
            excelMapper.saveEleth(flagOneList);
            excelMapper.saveThirteenth(flagOneList);
        }

        // 对于 flag 为 2 或其他的对象调用保存方法
        if (!otherFlagList.isEmpty()) {
            excelMapper.saveTwelfth(otherFlagList);
            excelMapper.saveSixteenth(otherFlagList);
            excelMapper.saveSeventeenth(otherFlagList);
            excelMapper.saveEighteenth(otherFlagList);
        }
        return 1;

    }

    @Override
    public ResponseEntity<byte[]> admissionDataDowload(List<String> ids,List<String> exportFields) {
        // 1. 根据 `ids` 查询 jlnu_admission_info（录取信息表）数据
        List<AdmissionInfo> admissionInfos = admissionInfoMapper.selectBatchIds(ids);

        // 2. 提取学号并查询 jlnu_teaching_archives（教学档案表）
        List<String> studentIds = admissionInfos.stream()
                .map(AdmissionInfo::getStudentId)
                .collect(Collectors.toList());
        List<JlnuTeachingArchives> teachingArchives = admissionInfoMapper.selectTecBatchIds(studentIds);

        // 3. 组装数据（合并两个表的数据）
        List<AdmissionInfoReqVo> exportDataList = mergeData(admissionInfos, teachingArchives);

        // 4. 生成 Excel 文件
        byte[] excelBytes = generateDynamicExcel(exportDataList,exportFields);

        // 5. 返回 ResponseEntity 响应给前端
        HttpHeaders headers = new HttpHeaders();
        headers.setContentDispositionFormData("attachment", "admission_data.xlsx");
        headers.setContentType(MediaType.APPLICATION_OCTET_STREAM);
        return new ResponseEntity<>(excelBytes, headers, HttpStatus.OK);

    }
    //    public byte[] generateDynamicExcel(List<AdmissionInfoReqVo> exportDataList, List<String> exportFields) {
//        if (exportDataList == null || exportDataList.isEmpty()) {
//            return new byte[0];
//        }
//        System.out.println("=== 开始生成 Excel ===");
//        System.out.println("导出字段数量: " + (exportFields != null ? exportFields.size() : 0));
//        try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
//            // 构建包含指定字段的Writer
//            WriteSheet writeSheet = EasyExcel.writerSheet("录取信息")
//                    .includeColumnFiledNames(exportFields)  // 关键方法：包含指定字段
//                    .build();
//
//            ExcelWriter excelWriter = EasyExcel.write(outputStream, AdmissionInfoReqVo.class)
//                    .build();
//
//            excelWriter.write(exportDataList, writeSheet);
//            excelWriter.finish();
//
//            return outputStream.toByteArray();
//        } catch (Exception e) {
//            throw new RuntimeException("生成Excel失败", e);
//        }
//    }
    public byte[] generateDynamicExcel(List<AdmissionInfoReqVo> exportDataList, List<String> exportFields) {
        if (exportDataList == null || exportDataList.isEmpty()) {
            return new byte[0];
        }

        System.out.println("=== 开始生成 Excel（动态字段）===");
        System.out.println("导出字段数量: " + (exportFields != null ? exportFields.size() : 0));

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        Workbook workbook = null;

        try {
            // 第一步：使用EasyExcel生成基础Excel
            ExcelWriter excelWriter = EasyExcel.write(outputStream, AdmissionInfoReqVo.class)
                    .registerWriteHandler(new GrayStyleHandler(34)) // 灰色样式
                    .build();

            WriteSheet writeSheet = EasyExcel.writerSheet("录取信息")
                    .includeColumnFiledNames(exportFields)
                    .build();

            excelWriter.write(exportDataList, writeSheet);
            excelWriter.finish();

            System.out.println("=== EasyExcel 生成完成，开始添加保护 ===");

            // 第二步：使用POI添加工作表保护
            workbook = WorkbookFactory.create(new ByteArrayInputStream(outputStream.toByteArray()));
            Sheet sheet = workbook.getSheetAt(0);

            // 启用保护
            sheet.protectSheet("password");

            // 第三步：输出最终结果
            ByteArrayOutputStream finalOutputStream = new ByteArrayOutputStream();
            workbook.write(finalOutputStream);

            System.out.println("=== 动态Excel生成完成 ===");
            return finalOutputStream.toByteArray();

        } catch (Exception e) {
            System.err.println("生成Excel失败: " + e.getMessage());
            e.printStackTrace();
            // 发生异常时，尝试返回未保护的文件
            return outputStream.toByteArray();
        } finally {
            // 确保资源被释放
            if (workbook != null) {
                try {
                    workbook.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

    @Override
    public JlnuTeachingArchives selectByStudentId(String studentId) {
        return admissionInfoMapper.selectByStudentId(studentId);
    }

    @Override
    public void updateById(JlnuTeachingArchives existingRecord) {
         admissionInfoMapper.updateById(existingRecord);
    }

    @Override
    public void insert(JlnuTeachingArchives newRecord) {
        admissionInfoMapper.insert(newRecord);
    }

    @Override
    public void insertImportLog(ImportFailLog failLog) {
        admissionInfoMapper.insertImportLog(failLog);
    }

    @Override
    public Page<ImportFailLog> getImportDataPage(int pageNum, int pageSize,Date startTime, Date endTime) {
        // 计算偏移量，注意 pageNum 从 1 开始，因此需要减去 1
        int offset = (pageNum - 1) * pageSize;

        // 查询当前页的数据
        List<ImportFailLog> data = admissionInfoMapper.selectPage(offset, pageSize,startTime,endTime);

        // 创建分页对象
        Page<ImportFailLog> page = new Page<>();
        page.setRecords(data);

        // 获取总记录数
        int totalCount = admissionInfoMapper.selectTotalCount(startTime,endTime);
        page.setTotal(totalCount);

        return page;
    }

    @Override
    public int batchUpdateAdmissionInfo(AdmissionInfoReqVo admissionInfoReqVo) {
        return admissionInfoMapper.batchUpdateAdmissionInfo(admissionInfoReqVo.getAdmissionInfoList(),admissionInfoReqVo.getTransferState());
    }

    private byte[] generateExcel(List<AdmissionInfoReqVo> exportDataList) {
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();

        System.out.println("=== 开始生成 Excel ===");

        EasyExcel.write(outputStream, AdmissionInfoReqVo.class)
                .registerWriteHandler(new GrayStyleHandler(34)) // 前 34 列变灰
                .sheet("录取信息")
                .doWrite(exportDataList);

        System.out.println("=== Excel 生成完成 ===");

        // 使用 POI 获取 Workbook 和 Sheet，然后启用保护
        Workbook workbook = null;
        try {
            workbook = WorkbookFactory.create(new ByteArrayInputStream(outputStream.toByteArray()));
            Sheet sheet = workbook.getSheetAt(0);  // 获取第一个 sheet

            // 启用保护
            sheet.protectSheet("password");  // 设置工作表保护密码

        } catch (Exception e) {
            e.printStackTrace();
        }

        // 将工作簿保存回 ByteArrayOutputStream
        ByteArrayOutputStream finalOutputStream = new ByteArrayOutputStream();
        try {
            workbook.write(finalOutputStream);  // 写入工作簿到流
        } catch (IOException e) {
            e.printStackTrace();
        }

        return finalOutputStream.toByteArray();
    }

    private List<AdmissionInfoReqVo> mergeData(List<AdmissionInfo> admissionInfos, List<JlnuTeachingArchives> teachingArchives) {
        // 构建 学号 -> 教学档案 的映射
        Map<String, JlnuTeachingArchives> archiveMap = teachingArchives.stream()
                .collect(Collectors.toMap(JlnuTeachingArchives::getStudentId, ta -> ta));

        // 遍历录取信息，合并教学档案数据
        List<AdmissionInfoReqVo> result = new ArrayList<>();
        for (AdmissionInfo admission : admissionInfos) {
            JlnuTeachingArchives archive = archiveMap.get(admission.getStudentId());
            AdmissionInfoReqVo exportData = new AdmissionInfoReqVo();

            // 录取信息数据
            BeanUtils.copyProperties(admission, exportData);

            // 教学档案数据
            if (archive != null) {
                BeanUtils.copyProperties(archive, exportData);
            }
            result.add(exportData);
        }
        return result;
    }


    @Override
    public IPage<ImportFailLog> getImportPage(int pageNum, int pageSize,String message,String name,String xueHao,String importType,
                                              String templateId) {
        // 1. 创建 Page 对象，传入当前页和每页大小
        Page<ImportFailLog> pageParam = new Page<>(pageNum, pageSize);
        IPage<ImportFailLog> resultPage = admissionInfoMapper.getImportPage(pageParam, message,name,xueHao,importType,templateId);
        return resultPage;
    }

    @Override
    public int importLogAdd(ImportFailLog param) {
        if (StringUtils.isEmpty(param.getImportType())){
            return -1;
        }
        long newId = System.currentTimeMillis(); // 或者使用雪花算法等分布式ID生成器
        param.setId(newId);
        param.setCreateTime(new Date());
        int i = admissionInfoMapper.importLogAdd(param);
        return i;
    }
}
